package com.example.javatwo.service.xs.wjy;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.example.javatwo.mapper.xs.wjy.IquotationDao;
import com.example.javatwo.pojo.xs.wjy.Historycheck;
import com.example.javatwo.pojo.xs.wjy.Quotation;

@Service
@Transactional(propagation = Propagation.REQUIRED)
public class IquotationBizImpl {
	@Autowired
	private IquotationDao quotationDao;

	public Quotation fundInfo(String deletedstate, int page) {

		return quotationDao.queryall(deletedstate, page);
	}

	public List<Quotation> findquotationlist() {
		return quotationDao.queryouwen();
	}

	public void savequotation(Quotation quotation) {
		if (quotationDao.loadquotation(quotation.getBillno()) == null
				|| quotationDao.loadquotation(quotation.getBillno()).getAuditstate().equals("未审核")) {
			quotationDao.insertquotation(quotation);
		}

		else {

			throw new RuntimeException("是审核状态,不能保存");
		}
	}

	public void updatequotation(Quotation quotation) {
		System.out.println(quotation.getBillno());
		if (quotationDao.loadquotation(quotation.getBillno()) != null
				&& quotationDao.loadquotation(quotation.getBillno()).getAuditstate().equals("未审核")) {
			quotationDao.deletequotationes(quotation.getBillno());
			quotationDao.deletequotation(quotation.getBillno());
			quotationDao.insertquotation(quotation);
		} else {
			throw new RuntimeException("你已经审核过了不能修改");
		}

	}

	public void deletequotation(String deletedstate, String billno) {
		if (quotationDao.loadquotation(billno) != null
				&& quotationDao.loadquotation(billno).getAuditstate().equals("未审核")) {
			quotationDao.updatequotation(deletedstate, billno);
		} else {
			throw new RuntimeException("你已经审核过了不能删除");
		}
	}

	public Integer countquotation() {
		return quotationDao.countquotation();
	}

	public void wjyshenhe(String billno) {

		if (quotationDao.loadquotation(billno) != null
				&& quotationDao.loadquotation(billno).getAuditstate().equals("未审核")) {
			quotationDao.wjyshenhe(billno);
		} else {

			throw new RuntimeException("你已经审核过了");
		}

	}

	public void wjyfanshenhe(String billno) {

		if (quotationDao.loadquotation(billno) != null
				&& quotationDao.loadquotation(billno).getAuditstate().equals("已审核")) {

			quotationDao.wjyfanshenhe(billno);
		} else {

			throw new RuntimeException("你没有审核过,不能反审核");
		}

	}
	public List<Historycheck>  loadquotationcust(String formalcust){
		return quotationDao.loadquotationcust(formalcust);
	}
}
